//
//  DataBaseManager.m
//  Leisure
//
//  Created by lanou3g on 16/4/11.
//  Copyright © 2016年 wenze. All rights reserved.
//

#import "DataBaseManager.h"

@implementation DataBaseManager

+ (instancetype)defaultManager{
    static DataBaseManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[DataBaseManager alloc]init];
    });
    return manager;
}

- (instancetype)init{
    if (self = [super init]) {
        // 获取documents 路径
        NSString *string =[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
        // 创建数据库路径
        NSString *path = [string stringByAppendingPathComponent:SqliteName];
        NSLog(@"%@",path);
        // 打开数据库
        self.dataBase = [[FMDatabase alloc]initWithPath:path];
        BOOL isOpen = [self.dataBase open];
        if (!isOpen) {
            NSLog(@"open sqlite error");
            
        }

    }
    return self;
}

- (void)closeDB{
    [self.dataBase close];
}

@end
